package com.lsyw.intergrate.controller;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.googlecode.aviator.AviatorEvaluator;
import com.lsyw.intergrate.common.Result;
import com.lsyw.intergrate.common.StringUtil;
import com.lsyw.intergrate.entity.JcyzSdShui;
import com.lsyw.intergrate.entity.JcyzSdShuiItem;
import com.lsyw.intergrate.entity.common.PageInfo;
import com.lsyw.intergrate.service.JcyzSdShuiItemService;
import com.lsyw.intergrate.service.JcyzSdShuiService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;

/**
 * <p>
 * 手动监测因子地下水 前端控制器
 * </p>
 *
 * @author 刘磊
 * @since 2024-01-03
 */
@Api(tags = "手动监测因子地下水")
@RestController
@RequestMapping("/jcyz-sd-shui")
public class JcyzSdShuiController {


    @Autowired
    private JcyzSdShuiService jcyzSdShuiService;
    @Autowired
    private JcyzSdShuiItemService jcyzSdShuiItemService;

    /**
     * 清洗数据
     */
    @GetMapping("/qingxi")

    @ApiOperation(value = "清洗数据", notes = "清洗数据", httpMethod = "GET")
    public Result qingxi() {
        List<JcyzSdShui> list = jcyzSdShuiService.list();
        for (JcyzSdShui shui : list) {

        }


        return Result.successResult(null);
    }

    /**
     * 通过id查询
     */
    @GetMapping("/get-by-id")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", required = true, paramType = "query", dataType = "String")
    })
    @ApiOperation(value = "通过id查询", notes = "通过id查询", httpMethod = "GET")
    public Result getById(String id) {
        JcyzSdShui jcyzSdShui = jcyzSdShuiService.getById(id);
        LambdaQueryWrapper<JcyzSdShuiItem> lambda = new QueryWrapper<JcyzSdShuiItem>().lambda();
        lambda.eq(JcyzSdShuiItem::getJcyzSdShuiId, id);
        lambda.eq(JcyzSdShuiItem::getDelFlag, 0);
        lambda.orderByAsc(JcyzSdShuiItem::getSort);
        List<JcyzSdShuiItem> itemList=jcyzSdShuiItemService.list(lambda);
        jcyzSdShui.setYiJcyzSdShuiItemList(itemList.stream().filter(e->(e.getType()==1)).collect(Collectors.toList()));
        jcyzSdShui.setErJcyzSdShuiItemList(itemList.stream().filter(e->(e.getType()==2)).collect(Collectors.toList()));
        jcyzSdShui.setSanJcyzSdShuiItemList(itemList.stream().filter(e->(e.getType()==3)).collect(Collectors.toList()));
        jcyzSdShui.setSiJcyzSdShuiItemList(itemList.stream().filter(e->(e.getType()==4)).collect(Collectors.toList()));
        jcyzSdShui.setWuJcyzSdShuiItemList(itemList.stream().filter(e->(e.getType()==5)).collect(Collectors.toList()));
        return Result.successResult(jcyzSdShui);
    }
    /**
     * 判断是否合格
     */
    @GetMapping("/qualified")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "category", value = "category", required = true, paramType = "query", dataType = "int"),
            @ApiImplicitParam(name = "value", value = "value", required = true, paramType = "query", dataType = "double")
    })
    @ApiOperation(value = "通过id查询", notes = "通过id查询", httpMethod = "GET")
    public Result qualified(String id,int category,double value) {
        JcyzSdShui jcyzSdShui =jcyzSdShuiService.getById(id);
        String query="";
        int type=1;
        //符合告警规则的消息向告警队列中推送
        switch (category){
            case 1:
                query=jcyzSdShui.getYiQuery();
                type=jcyzSdShui.getYiQueryType();
                break;
            case 2:
                query=jcyzSdShui.getErQuery();
                type=jcyzSdShui.getErQueryType();
                break;
            case 3:
                query=jcyzSdShui.getSanQuery();
                type=jcyzSdShui.getSanQueryType();
                break;
            case 4:
                query=jcyzSdShui.getSiQuery();
                type=jcyzSdShui.getSiQueryType();
                break;
            case 5:
                query=jcyzSdShui.getWuQuery();
                type=jcyzSdShui.getWuQueryType();
                break;
            default:
                break;
        }
        if (ObjectUtil.isNotNull(jcyzSdShui)&&type==2&&!StringUtil.isEmpty(query)) {
            Map<String, Object> env = new HashMap<String, Object>();
            env.put("'X'", value);
            return Result.successResult(AviatorEvaluator.execute(query, env));
        }else{
            return Result.successResult(true);
        }
    }

    /**
     * 新增
     */
    @PostMapping("/save")
    @ApiOperation(value = "新增", notes = "新增", httpMethod = "POST")
    public Result save(@RequestBody JcyzSdShui jcyzSdShui) {
        jcyzSdShui.setGmtCreate(new Date());
        jcyzSdShui.setDelFlag(0);
        jcyzSdShuiService.save(jcyzSdShui);

        if (!CollectionUtils.isEmpty(jcyzSdShui.getYiJcyzSdShuiItemList())) {
            //判断条件
            final String[] queryCondition = {""};
            //判断条件展示
            final String[] queryConditionShow = {""};
            AtomicInteger sort = new AtomicInteger(1);
            jcyzSdShui.getYiJcyzSdShuiItemList().forEach(e -> {
                queryCondition[0] += "X" + this.getSignByOperator(e.getOperator()) + e.getValue();
                //拼接用于展示的字符串
                queryConditionShow[0] += e.getOperator() + e.getValue() + ",";
                //条件之间拼接符号
                //筛选方式 0所有   1任意
                if (jcyzSdShui.getYiQueryType() == 1) {
                    queryCondition[0] += "&&";
                } else {
                    queryCondition[0] += "||";
                }
                e.setId(null);
                e.setDelFlag(0);
                e.setStatus(1);
                e.setGmtCreate(new Date());
                e.setJcyzSdShuiId(jcyzSdShui.getId());
                e.setType(1);
                e.setSort(sort.getAndIncrement());
                jcyzSdShuiItemService.save(e);
            });
            jcyzSdShui.setYiQueryShow(StringUtil.strTrim(queryConditionShow[0], ","));
            jcyzSdShui.setYiQuery(StringUtil.strTrim(StringUtil.strTrim(StringUtil.strTrim(StringUtil.strTrim(queryCondition[0], "|"), "|"), "&"), "&"));
        }
        if (!CollectionUtils.isEmpty(jcyzSdShui.getErJcyzSdShuiItemList())) {
            //判断条件
            final String[] queryCondition = {""};
            //判断条件展示
            final String[] queryConditionShow = {""};
            AtomicInteger sort = new AtomicInteger(1);
            jcyzSdShui.getErJcyzSdShuiItemList().forEach(e -> {
                queryCondition[0] += "X" + this.getSignByOperator(e.getOperator()) + e.getValue();
                //拼接用于展示的字符串
                queryConditionShow[0] += e.getOperator() + e.getValue() + ",";
                //条件之间拼接符号
                //筛选方式 0所有   1任意
                if (jcyzSdShui.getErQueryType() == 1) {
                    queryCondition[0] += "&&";
                } else {
                    queryCondition[0] += "||";
                }
                e.setId(null);
                e.setDelFlag(0);
                e.setStatus(1);
                e.setGmtCreate(new Date());
                e.setJcyzSdShuiId(jcyzSdShui.getId());
                e.setType(2);
                e.setSort(sort.getAndIncrement());
                jcyzSdShuiItemService.save(e);
            });
            jcyzSdShui.setErQueryShow(StringUtil.strTrim(queryConditionShow[0], ","));
            jcyzSdShui.setErQuery(StringUtil.strTrim(StringUtil.strTrim(StringUtil.strTrim(StringUtil.strTrim(queryCondition[0], "|"), "|"), "&"), "&"));
        }
        if (!CollectionUtils.isEmpty(jcyzSdShui.getSanJcyzSdShuiItemList())) {
            //判断条件
            final String[] queryCondition = {""};
            //判断条件展示
            final String[] queryConditionShow = {""};
            AtomicInteger sort = new AtomicInteger(1);
            jcyzSdShui.getSanJcyzSdShuiItemList().forEach(e -> {
                queryCondition[0] += "X" + this.getSignByOperator(e.getOperator()) + e.getValue();
                //拼接用于展示的字符串
                queryConditionShow[0] += e.getOperator() + e.getValue() + ",";
                //条件之间拼接符号
                //筛选方式 0所有   1任意
                if (jcyzSdShui.getSanQueryType() == 1) {
                    queryCondition[0] += "&&";
                } else {
                    queryCondition[0] += "||";
                }
                e.setId(null);
                e.setDelFlag(0);
                e.setStatus(1);
                e.setGmtCreate(new Date());
                e.setJcyzSdShuiId(jcyzSdShui.getId());
                e.setType(3);
                e.setSort(sort.getAndIncrement());
                jcyzSdShuiItemService.save(e);
            });
            jcyzSdShui.setSanQueryShow(StringUtil.strTrim(queryConditionShow[0], ","));
            jcyzSdShui.setSanQuery(StringUtil.strTrim(StringUtil.strTrim(StringUtil.strTrim(StringUtil.strTrim(queryCondition[0], "|"), "|"), "&"), "&"));
        }
        if (!CollectionUtils.isEmpty(jcyzSdShui.getSiJcyzSdShuiItemList())) {
            //判断条件
            final String[] queryCondition = {""};
            //判断条件展示
            final String[] queryConditionShow = {""};
            AtomicInteger sort = new AtomicInteger(1);
            jcyzSdShui.getSiJcyzSdShuiItemList().forEach(e -> {
                queryCondition[0] += "X" + this.getSignByOperator(e.getOperator()) + e.getValue();
                //拼接用于展示的字符串
                queryConditionShow[0] += e.getOperator() + e.getValue() + ",";
                //条件之间拼接符号
                //筛选方式 0所有   1任意
                if (jcyzSdShui.getSiQueryType() == 1) {
                    queryCondition[0] += "&&";
                } else {
                    queryCondition[0] += "||";
                }
                e.setId(null);
                e.setDelFlag(0);
                e.setStatus(1);
                e.setGmtCreate(new Date());
                e.setJcyzSdShuiId(jcyzSdShui.getId());
                e.setType(4);
                e.setSort(sort.getAndIncrement());
                jcyzSdShuiItemService.save(e);
            });
            jcyzSdShui.setSiQueryShow(StringUtil.strTrim(queryConditionShow[0], ","));
            jcyzSdShui.setSiQuery(StringUtil.strTrim(StringUtil.strTrim(StringUtil.strTrim(StringUtil.strTrim(queryCondition[0], "|"), "|"), "&"), "&"));
        }
        if (!CollectionUtils.isEmpty(jcyzSdShui.getWuJcyzSdShuiItemList())) {
            //判断条件
            final String[] queryCondition = {""};
            //判断条件展示
            final String[] queryConditionShow = {""};
            AtomicInteger sort = new AtomicInteger(1);
            jcyzSdShui.getWuJcyzSdShuiItemList().forEach(e -> {
                queryCondition[0] += "X" + this.getSignByOperator(e.getOperator()) + e.getValue();
                //拼接用于展示的字符串
                queryConditionShow[0] += e.getOperator() + e.getValue() + ",";
                //条件之间拼接符号
                //筛选方式 0所有   1任意
                if (jcyzSdShui.getWuQueryType() == 1) {
                    queryCondition[0] += "&&";
                } else {
                    queryCondition[0] += "||";
                }
                e.setId(null);
                e.setDelFlag(0);
                e.setStatus(1);
                e.setGmtCreate(new Date());
                e.setJcyzSdShuiId(jcyzSdShui.getId());
                e.setType(5);
                e.setSort(sort.getAndIncrement());
                jcyzSdShuiItemService.save(e);
            });
            jcyzSdShui.setWuQueryShow(StringUtil.strTrim(queryConditionShow[0], ","));
            jcyzSdShui.setWuQuery(StringUtil.strTrim(StringUtil.strTrim(StringUtil.strTrim(StringUtil.strTrim(queryCondition[0], "|"), "|"), "&"), "&"));
        }
        jcyzSdShuiService.updateById(jcyzSdShui);
        return Result.successResult(null);
    }

    /**
     * 根据运算符号得到用于判断的运算符号
     *
     * @param operator
     * @return
     */
    public String getSignByOperator(String operator) {
        if (operator == null) {
            return "未知";
        }
        if ("=".equals(operator)) {
            //单等号  变成双等号
            operator = "==";
        } else if ("≠".equals(operator)) {
            //不等于
            operator = "!=";
        }
        return operator;
    }


    /**
     * 通过id删除
     */
    @GetMapping("/delete-by-id/{id}")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", required = true, paramType = "query", dataType = "String")
    })
    @ApiOperation(value = "通过id删除", notes = "通过id删除", httpMethod = "GET")
    public Result delete(@PathVariable(value = "id") String id) {
        jcyzSdShuiService.removeById(id);
        LambdaQueryWrapper<JcyzSdShuiItem> lambda = new QueryWrapper<JcyzSdShuiItem>().lambda();
        lambda.eq(JcyzSdShuiItem::getJcyzSdShuiId, id);
        lambda.eq(JcyzSdShuiItem::getDelFlag, 0);
        JcyzSdShuiItem jcyzSdShuiItem = new JcyzSdShuiItem();
        jcyzSdShuiItem.setDelFlag(1);
        jcyzSdShuiItem.setGmtModified(new Date());
        jcyzSdShuiItemService.update(jcyzSdShuiItem, lambda);
        return Result.successResult(null);
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    @ApiOperation(value = "修改", notes = "修改", httpMethod = "POST")
    public Result updateById(@RequestBody JcyzSdShui jcyzSdShui) {
        jcyzSdShui.setGmtModified(new Date());
        jcyzSdShuiService.updateById(jcyzSdShui);
        LambdaQueryWrapper<JcyzSdShuiItem> lambda = new QueryWrapper<JcyzSdShuiItem>().lambda();
        lambda.eq(JcyzSdShuiItem::getJcyzSdShuiId, jcyzSdShui.getId());
        lambda.eq(JcyzSdShuiItem::getDelFlag, 0);
        JcyzSdShuiItem jcyzSdShuiItem = new JcyzSdShuiItem();
        jcyzSdShuiItem.setDelFlag(1);
        jcyzSdShuiItem.setGmtModified(new Date());
        jcyzSdShuiItemService.update(jcyzSdShuiItem, lambda);
        if (!CollectionUtils.isEmpty(jcyzSdShui.getYiJcyzSdShuiItemList())) {
            //判断条件
            final String[] queryCondition = {""};
            //判断条件展示
            final String[] queryConditionShow = {""};
            AtomicInteger sort = new AtomicInteger(1);
            jcyzSdShui.getYiJcyzSdShuiItemList().forEach(e -> {
                queryCondition[0] += "X" + this.getSignByOperator(e.getOperator()) + e.getValue();
                //拼接用于展示的字符串
                queryConditionShow[0] += e.getOperator() + e.getValue() + ",";
                //条件之间拼接符号
                //筛选方式 0所有   1任意
                if (jcyzSdShui.getYiQueryType() == 1) {
                    queryCondition[0] += "&&";
                } else {
                    queryCondition[0] += "||";
                }
                e.setId(null);
                e.setDelFlag(0);
                e.setStatus(1);
                e.setGmtCreate(new Date());
                e.setJcyzSdShuiId(jcyzSdShui.getId());
                e.setType(1);
                e.setSort(sort.getAndIncrement());
                jcyzSdShuiItemService.save(e);
            });
            jcyzSdShui.setYiQueryShow(StringUtil.strTrim(queryConditionShow[0], ","));
            jcyzSdShui.setYiQuery(StringUtil.strTrim(StringUtil.strTrim(StringUtil.strTrim(StringUtil.strTrim(queryCondition[0], "|"), "|"), "&"), "&"));
        }else{
            jcyzSdShui.setYiQueryShow(null);
            jcyzSdShui.setYiQuery(null);
        }
        if (!CollectionUtils.isEmpty(jcyzSdShui.getErJcyzSdShuiItemList())) {
            //判断条件
            final String[] queryCondition = {""};
            //判断条件展示
            final String[] queryConditionShow = {""};
            AtomicInteger sort = new AtomicInteger(1);
            jcyzSdShui.getErJcyzSdShuiItemList().forEach(e -> {
                queryCondition[0] += "X" + this.getSignByOperator(e.getOperator()) + e.getValue();
                //拼接用于展示的字符串
                queryConditionShow[0] += e.getOperator() + e.getValue() + ",";
                //条件之间拼接符号
                //筛选方式 0所有   1任意
                if (jcyzSdShui.getErQueryType() == 1) {
                    queryCondition[0] += "&&";
                } else {
                    queryCondition[0] += "||";
                }
                e.setId(null);
                e.setDelFlag(0);
                e.setStatus(1);
                e.setGmtCreate(new Date());
                e.setJcyzSdShuiId(jcyzSdShui.getId());
                e.setType(2);
                e.setSort(sort.getAndIncrement());
                jcyzSdShuiItemService.save(e);
            });
            jcyzSdShui.setErQueryShow(StringUtil.strTrim(queryConditionShow[0], ","));
            jcyzSdShui.setErQuery(StringUtil.strTrim(StringUtil.strTrim(StringUtil.strTrim(StringUtil.strTrim(queryCondition[0], "|"), "|"), "&"), "&"));
        }else{
            jcyzSdShui.setErQueryShow(null);
            jcyzSdShui.setErQuery(null);
        }
        if (!CollectionUtils.isEmpty(jcyzSdShui.getSanJcyzSdShuiItemList())) {
            //判断条件
            final String[] queryCondition = {""};
            //判断条件展示
            final String[] queryConditionShow = {""};
            AtomicInteger sort = new AtomicInteger(1);
            jcyzSdShui.getSanJcyzSdShuiItemList().forEach(e -> {
                queryCondition[0] += "X" + this.getSignByOperator(e.getOperator()) + e.getValue();
                //拼接用于展示的字符串
                queryConditionShow[0] += e.getOperator() + e.getValue() + ",";
                //条件之间拼接符号
                //筛选方式 0所有   1任意
                if (jcyzSdShui.getSanQueryType() == 1) {
                    queryCondition[0] += "&&";
                } else {
                    queryCondition[0] += "||";
                }
                e.setId(null);
                e.setDelFlag(0);
                e.setStatus(1);
                e.setGmtCreate(new Date());
                e.setJcyzSdShuiId(jcyzSdShui.getId());
                e.setType(3);
                e.setSort(sort.getAndIncrement());
                jcyzSdShuiItemService.save(e);
            });
            jcyzSdShui.setSanQueryShow(StringUtil.strTrim(queryConditionShow[0], ","));
            jcyzSdShui.setSanQuery(StringUtil.strTrim(StringUtil.strTrim(StringUtil.strTrim(StringUtil.strTrim(queryCondition[0], "|"), "|"), "&"), "&"));
        }else{
            jcyzSdShui.setSanQueryShow(null);
            jcyzSdShui.setSanQuery(null);
        }
        if (!CollectionUtils.isEmpty(jcyzSdShui.getSiJcyzSdShuiItemList())) {
            //判断条件
            final String[] queryCondition = {""};
            //判断条件展示
            final String[] queryConditionShow = {""};
            AtomicInteger sort = new AtomicInteger(1);
            jcyzSdShui.getSiJcyzSdShuiItemList().forEach(e -> {
                queryCondition[0] += "X" + this.getSignByOperator(e.getOperator()) + e.getValue();
                //拼接用于展示的字符串
                queryConditionShow[0] += e.getOperator() + e.getValue() + ",";
                //条件之间拼接符号
                //筛选方式 0所有   1任意
                if (jcyzSdShui.getSiQueryType() == 1) {
                    queryCondition[0] += "&&";
                } else {
                    queryCondition[0] += "||";
                }
                e.setId(null);
                e.setDelFlag(0);
                e.setStatus(1);
                e.setGmtCreate(new Date());
                e.setJcyzSdShuiId(jcyzSdShui.getId());
                e.setType(4);
                e.setSort(sort.getAndIncrement());
                jcyzSdShuiItemService.save(e);
            });
            jcyzSdShui.setSiQueryShow(StringUtil.strTrim(queryConditionShow[0], ","));
            jcyzSdShui.setSiQuery(StringUtil.strTrim(StringUtil.strTrim(StringUtil.strTrim(StringUtil.strTrim(queryCondition[0], "|"), "|"), "&"), "&"));
        }else{
            jcyzSdShui.setSiQueryShow(null);
            jcyzSdShui.setSiQuery(null);
        }
        if (!CollectionUtils.isEmpty(jcyzSdShui.getWuJcyzSdShuiItemList())) {
            //判断条件
            final String[] queryCondition = {""};
            //判断条件展示
            final String[] queryConditionShow = {""};
            AtomicInteger sort = new AtomicInteger(1);
            jcyzSdShui.getWuJcyzSdShuiItemList().forEach(e -> {
                queryCondition[0] += "X" + this.getSignByOperator(e.getOperator()) + e.getValue();
                //拼接用于展示的字符串
                queryConditionShow[0] += e.getOperator() + e.getValue() + ",";
                //条件之间拼接符号
                //筛选方式 0所有   1任意
                if (jcyzSdShui.getWuQueryType() == 1) {
                    queryCondition[0] += "&&";
                } else {
                    queryCondition[0] += "||";
                }
                e.setId(null);
                e.setDelFlag(0);
                e.setStatus(1);
                e.setGmtCreate(new Date());
                e.setJcyzSdShuiId(jcyzSdShui.getId());
                e.setType(5);
                e.setSort(sort.getAndIncrement());
                jcyzSdShuiItemService.save(e);
            });
            jcyzSdShui.setWuQueryShow(StringUtil.strTrim(queryConditionShow[0], ","));
            jcyzSdShui.setWuQuery(StringUtil.strTrim(StringUtil.strTrim(StringUtil.strTrim(StringUtil.strTrim(queryCondition[0], "|"), "|"), "&"), "&"));
        }else{
            jcyzSdShui.setWuQueryShow(null);
            jcyzSdShui.setWuQuery(null);
        }
        jcyzSdShuiService.updateById(jcyzSdShui);
        return Result.successResult(null);
    }


    /**
     * 查询列表
     */
    @PostMapping("/list")
    @ApiOperation(value = "查询列表", notes = "查询列表", httpMethod = "POST")
    public Result list(@RequestBody JcyzSdShuiReqVo jcyzSdShui) {
        final LambdaQueryWrapper<JcyzSdShui> lambda = new QueryWrapper<JcyzSdShui>().lambda();
        this.buildCondition(lambda, jcyzSdShui);
        return Result.successResult(jcyzSdShuiService.list(lambda));
    }

    /**
     * 分页查询
     */
    @PostMapping("/page")
    @ApiOperation(value = "分页查询", notes = "分页查询", httpMethod = "POST")
    public Result page(@RequestBody PageInfo pageInfo) {
        Page<JcyzSdShui> page = new Page<>();
        page.setSize(pageInfo.getPageSize());
        page.setCurrent(pageInfo.getPageNum());
        Map<String, Object> condition = pageInfo.getCondition();
        LambdaQueryWrapper<JcyzSdShui> lambda = new QueryWrapper<JcyzSdShui>().lambda();
        lambda.eq(JcyzSdShui::getDelFlag, 0);
        if (condition.get("name") != null && !StringUtils.isEmpty(condition.get("name").toString())) {
            lambda.like(JcyzSdShui::getName, condition.get("name"));
        }
        if (condition.get("isGb") != null && !StringUtils.isEmpty(condition.get("isGb").toString())) {
            lambda.like(JcyzSdShui::getIsGb, condition.get("isGb"));
        }
        lambda.orderBy(true, false, JcyzSdShui::getGmtCreate);
        return Result.successResult(this.jcyzSdShuiService.page(page, lambda));
    }


    /**
     * 获取分类
     */
    @PostMapping("/type/list")
    // @GetMapping("/delete-by-id")
    @ApiOperation(value = "获取分类", notes = "获取分类", httpMethod = "POST")
    public Result typeList() {
        LambdaQueryWrapper<JcyzSdShui> lambda = new QueryWrapper<JcyzSdShui>().lambda();
        lambda.eq(JcyzSdShui::getDelFlag, 0).groupBy(JcyzSdShui::getJcType);
        List<JcyzSdShui> list = this.jcyzSdShuiService.list(lambda);
        List<String> type = new ArrayList<>();
        for (JcyzSdShui jcyzSdTr : list
        ) {
            type.add(jcyzSdTr.getJcType());
        }
        return Result.successResult(type);
    }

    /**
     * 根据类型获取因子
     */
    @GetMapping("/listByType")
    // @GetMapping("/delete-by-id")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "jcType", value = "jcType", required = true, paramType = "query", dataType = "String")
    })
    @ApiOperation(value = "根据类型获取因子", notes = "根据类型获取因子", httpMethod = "GET")
    public Result listByType(String jcType) {
        LambdaQueryWrapper<JcyzSdShui> lambda = new QueryWrapper<JcyzSdShui>().lambda();
        lambda.eq(JcyzSdShui::getDelFlag, 0).groupBy(JcyzSdShui::getJcType).eq(JcyzSdShui::getJcType, jcType);
        List<JcyzSdShui> list = this.jcyzSdShuiService.list(lambda);
        return Result.successResult(list);
    }

    /**
     * 构造查询条件
     *
     * @param lambda
     * @param param
     */
    private void buildCondition(LambdaQueryWrapper<JcyzSdShui> lambda, JcyzSdShuiReqVo param) {
        if (!StringUtils.isEmpty(param.getId())) {
            lambda.eq(JcyzSdShui::getId, param.getId());
        }
        if (!StringUtils.isEmpty(param.getName())) {
            lambda.eq(JcyzSdShui::getName, param.getName());
        }
        if (!StringUtils.isEmpty(param.getType())) {
            lambda.eq(JcyzSdShui::getType, param.getType());
        }
        if (!StringUtils.isEmpty(param.getJcType())) {
            lambda.eq(JcyzSdShui::getJcType, param.getJcType());
        }
        if (!StringUtils.isEmpty(param.getGmtCreateUser())) {
            lambda.eq(JcyzSdShui::getGmtCreateUser, param.getGmtCreateUser());
        }
        if (!CollectionUtils.isEmpty(param.getGmtCreateList())) {
            lambda.ge(JcyzSdShui::getGmtCreate, param.getGmtCreateList().get(0));
            lambda.le(JcyzSdShui::getGmtCreate, param.getGmtCreateList().get(1));
        }
        if (!StringUtils.isEmpty(param.getGmtModifiedUser())) {
            lambda.eq(JcyzSdShui::getGmtModifiedUser, param.getGmtModifiedUser());
        }
        if (!CollectionUtils.isEmpty(param.getGmtModifiedList())) {
            lambda.ge(JcyzSdShui::getGmtModified, param.getGmtModifiedList().get(0));
            lambda.le(JcyzSdShui::getGmtModified, param.getGmtModifiedList().get(1));
        }
        if (!StringUtils.isEmpty(param.getDelFlag())) {
            lambda.eq(JcyzSdShui::getDelFlag, param.getDelFlag());
        }
        if (!StringUtils.isEmpty(param.getNo())) {
            lambda.eq(JcyzSdShui::getNo, param.getNo());
        }
        if (!StringUtils.isEmpty(param.getYi())) {
            lambda.eq(JcyzSdShui::getYi, param.getYi());
        }
        if (!StringUtils.isEmpty(param.getEr())) {
            lambda.eq(JcyzSdShui::getEr, param.getEr());
        }
        if (!StringUtils.isEmpty(param.getSan())) {
            lambda.eq(JcyzSdShui::getSan, param.getSan());
        }
        if (!StringUtils.isEmpty(param.getSi())) {
            lambda.eq(JcyzSdShui::getSi, param.getSi());
        }
        if (!StringUtils.isEmpty(param.getWu())) {
            lambda.eq(JcyzSdShui::getWu, param.getWu());
        }
        lambda.orderBy(true, false, JcyzSdShui::getId);
    }


    /**
     * 请求model
     */
    @Data
    @AllArgsConstructor
    private static class JcyzSdShuiReqVo extends JcyzSdShui {
        private List<String> gmtCreateList; // 创建时间起止
        private List<String> gmtModifiedList; // 更新时间起止
    }


}
